How to retrieve string array from an oleMethod

I am trying to retrieve a list of headings from an exported MS Word document so that I can automatically insert cross references.

There is a MS Word VBA function ActiveDocument.GetCrossReferenceItems() that returns an array of strings.

Does anyone know how to retrieve this list of string from DXL? 

I've tried to use the oleMethod function, but I can't figure out how to configure it to work with an array of strings as the return value.


TheNybbler - Thu Nov 19 10:00:21 EST 2015

Re: How to retrieve string array from an oleMethod
Mathias Mamsch - Thu Nov 19 11:58:34 EST 2015

Unfortunately Telelogic / IBM never bothered to complete their COM interface to support arrays. Therefore you cannot use COM functions that take array parameters or return them. I think people have worked around this, by using other functions to reach the same goal, Invoke Macros, put their COM interactions to another language and even write their own COM server that would expose the interface differently.

I have no ready solution for you... Maybe someone else has? Regards, Mathias

Re: How to retrieve string array from an oleMethod
TheNybbler - Fri Nov 20 03:34:41 EST 2015

Mathias Mamsch - Thu Nov 19 11:58:34 EST 2015

Unfortunately Telelogic / IBM never bothered to complete their COM interface to support arrays. Therefore you cannot use COM functions that take array parameters or return them. I think people have worked around this, by using other functions to reach the same goal, Invoke Macros, put their COM interactions to another language and even write their own COM server that would expose the interface differently.

I have no ready solution for you... Maybe someone else has? Regards, Mathias

Hi Mathias,

I thought that may be the case. I'm trying to develop a workaround and seem to have encountered a related problem.

I'm trying to retrieve the value of a property in the Word object model that is of type Variant. The data being returned in the Variant is actually a string, but the oleGet method does not seem to be able to retrieve the string value.

This is the code I'm using:

 

string value;

oleGet(oleObj, "Style", value);

 

Does the oleGet method not support Variant data types?

 

Re: How to retrieve string array from an oleMethod
Mathias Mamsch - Fri Nov 20 03:40:04 EST 2015

TheNybbler - Fri Nov 20 03:34:41 EST 2015

Hi Mathias,

I thought that may be the case. I'm trying to develop a workaround and seem to have encountered a related problem.

I'm trying to retrieve the value of a property in the Word object model that is of type Variant. The data being returned in the Variant is actually a string, but the oleGet method does not seem to be able to retrieve the string value.

This is the code I'm using:

 

string value;

oleGet(oleObj, "Style", value);

 

Does the oleGet method not support Variant data types?

 

Sounds not like a familiar problem to me. From which Object/Class are you requesting the style property?

Re: How to retrieve string array from an oleMethod
TheNybbler - Fri Nov 20 03:42:01 EST 2015

Mathias Mamsch - Fri Nov 20 03:40:04 EST 2015

Sounds not like a familiar problem to me. From which Object/Class are you requesting the style property?

It is in the MSWord object model Paragraph.Style property (see https://msdn.microsoft.com/EN-US/library/office/ff835808.aspx)

 

Re: How to retrieve string array from an oleMethod
TheNybbler - Fri Nov 20 03:55:02 EST 2015

TheNybbler - Fri Nov 20 03:42:01 EST 2015

It is in the MSWord object model Paragraph.Style property (see https://msdn.microsoft.com/EN-US/library/office/ff835808.aspx)

 

It seems that this now works if I set the type to an OleAutoObj.

This is odd as, it does not work when trying to use Paragraph.Range.Style (which is what I was using originally).

 

Re: How to retrieve string array from an oleMethod
Mathias Mamsch - Fri Nov 20 04:45:11 EST 2015

TheNybbler - Fri Nov 20 03:55:02 EST 2015

It seems that this now works if I set the type to an OleAutoObj.

This is odd as, it does not work when trying to use Paragraph.Range.Style (which is what I was using originally).

 

Don't be confused by the OLE Object Model. A lot of Objects have "default properties". Like Document.Paragraphs(1) which is an abbreviation for Document.Paragraphs.Items(1). The same is true for the style property. You can set it using the default property, but you cannot read it, it seems. Regards, Mathias

    void check (string s) { if (!null s) error s }

    OleAutoObj app, doc, pars, par, rng, style
    OleAutoArgs args
    args = create()

    app = oleGetAutoObject("word.application")
    check oleGet(app, "ActiveDocument", doc)

    check oleGet(doc, "Paragraphs",pars)
    put(args, 1)
    check oleMethod(pars, "Item",args, par)

    check oleGet(par, "Range",rng)

    string sText = "Here"; 
    check olePut(rng, "Text", sText)

    string sStyleName = "Standard"
    check olePut(rng, "Style", sStyleName)

    string sStyle = ""; 
    check oleGet (rng, "Style", style); 

    check oleGet(style, "NameLocal", sStyle)
    print "Read: " sStyle "\n"

    oleCloseAutoObject(rng); 
    oleCloseAutoObject(par);    
    oleCloseAutoObject(pars);

    oleCloseAutoObject(doc);
    oleCloseAutoObject(app)